# 从list继承 __getitem__

class CounterList(list):
    '带访问次数的list'

    def __init__(self, *args):
        super().__init__(*args)
        self.counter = 0

    def __getitem__(self, item):
        self.counter += 1
        return super(CounterList, self).__getitem__(item)


cl = CounterList(range(10))
print(cl, cl.counter)
cl.reverse()
print(cl, cl.counter)
print(cl[1])
print(f'cl.counter={cl.counter}')  # cl.counter=1
